package Swing.src.landlord;

import java.util.*;

public class PlayGame2 {
    //拿牌
//洗牌
//发牌
//看牌
    //序号
    static ArrayList<String> list = new ArrayList<>();
    static TreeMap<String, Integer> treeMap = new TreeMap<>();

    static {
        String[] color = {"♦", "❤", "♣", "♠"};
        String[] number = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        for (String c : color) {
            for (String n : number) {
                list.add(c + n);
            }
        }
        list.add(" 小王");
        list.add(" 大王");
        treeMap.put("J", 11);
        treeMap.put("Q", 12);
        treeMap.put("K", 13);
        treeMap.put("A", 14);
        treeMap.put("2", 15);
        treeMap.put("小王", 50);
        treeMap.put("大王", 100);
    }

    PlayGame2() {
        Collections.shuffle(list);
        ArrayList<String> load = new ArrayList<>();
        ArrayList<String> player1 = new ArrayList<>();
        ArrayList<String> player2 = new ArrayList<>();
        ArrayList<String> player3 = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if (i <= 2) {
                load.add(list.get(i));
            } else if (i % 3 == 0) {
                player1.add(list.get(i));
            } else if (i % 3 == 1) {
                player2.add(list.get(i));
            } else if (i % 3 == 2) {
                player3.add(list.get(i));
            }
        }
        order(player1);
        order(player2);
        order(player3);
        order(load);
        lookPlayer("蔡徐坤", player1);
        lookPlayer("丁真", player2);
        lookPlayer("肖战", player3);
        lookPlayer("底牌", load);
    }

    public void lookPlayer(String name, ArrayList<String> list) {
        System.out.print(name + ":");
        for (String l : list) {
            System.out.print(l + ' ');
        }
        System.out.println();
    }

    //    排序方法
    public void order(ArrayList<String> arrayList) {
        Collections.sort(arrayList, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
//                o1
                String c1 = o1.substring(0, 1);
                int v1 = getValue(o1);
//                o2
                String c2 = o2.substring(0, 1);
                int v2 = getValue(o2);
                return v1 == v2 ? c1.compareTo(c2) : v1 - v2;
            }
        });
    }

    //获取权值
    public int getValue(String poker) {
        String number = poker.substring(1);
        if (treeMap.containsKey(number)) {
            return treeMap.get(number);
        } else {
            return Integer.parseInt(number);
        }
    }

}
